﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sqlsearcher.Services
{
    public class TextHandler
    {
        public static void SetCmdKey(Keys keyData, TextBox txtContent)
        {
            if (keyData == (Keys.Control | Keys.A))
            {
                txtContent.SelectAll();
            }
            else if (keyData == (Keys.Control | Keys.C))
            {
                Clipboard.SetText(txtContent.SelectedText);
            }
            else if (keyData == (Keys.Control | Keys.V))
            {
                IDataObject iData = Clipboard.GetDataObject();
                if (iData.GetDataPresent(DataFormats.Text))
                {
                    var index = txtContent.SelectionStart;
                    var vString = Clipboard.GetText(TextDataFormat.Text);
                    txtContent.Text = txtContent.Text.Insert(index, vString);
                    txtContent.SelectionStart = index + vString.Length;
                }
            }
            else if (keyData == (Keys.Control | Keys.X))
            {
                txtContent.Cut();
            }
            else if (keyData == (Keys.Control | Keys.Z))
            {
                txtContent.Undo();
            }
        }

        public static void SetCmdKey(Keys keyData, RichTextBox txtContent)
        {
            if (keyData == (Keys.Control | Keys.A))
            {
                txtContent.SelectAll();
            }
            else if (keyData == (Keys.Control | Keys.C))
            {
                Clipboard.SetText(txtContent.SelectedText);
            }
            else if (keyData == (Keys.Control | Keys.V))
            {
                IDataObject iData = Clipboard.GetDataObject();
                if (iData.GetDataPresent(DataFormats.Text))
                {
                    var index = txtContent.SelectionStart;
                    var vString = Clipboard.GetText(TextDataFormat.Text);
                    txtContent.Text = txtContent.Text.Insert(index, vString);
                    txtContent.SelectionStart = index + vString.Length;
                }
            }
            else if (keyData == (Keys.Control | Keys.X))
            {
                txtContent.Cut();
            }
            else if (keyData == (Keys.Control | Keys.Z))
            {
                txtContent.Undo();
            }
        }
    }
}
